#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main()
{
    pid_t pid = 0;
    int a = 1;
    int b = 0;
    int status = 0;

    printf("parent = %d\n", getpid());

    if ((pid = fork()) == 0) exit(-1);

    printf("child = %d\n", pid);

    if ((pid = fork()) == 0) abort();

    printf("child = %d\n", pid);

    if ((pid = fork()) == 0) a = a / b, exit(1);

    printf("child = %d\n", pid);

    sleep(3);

    while ((pid = wait(&status)) > 0) {
        if (WIFEXITED(status)) {
            printf("Normal - child = %d, code = %d\n", \
                    pid, (char)WEXITSTATUS(status));
        } else if (WIFSIGNALED(status)) {
            printf("Signaled - child = %d, code = %d\n", \
                    pid, (char)WTERMSIG(status));
        } else {
            printf("Paused - child = %d, code = %d\n", \
                    pid, (char)WSTOPSIG(status));
        }
    }

    return 0;
}
